/*
@author: stanfor
@date: 2022/8/22 17:30
@Version: 1.0
@last modify time : 2022/8/22 17:30
*/

import React, { FC, ReactElement } from 'react';
import { Checkbox, Col, Form, CheckboxGroupProps } from 'antd';
import { getRulesConfig, commonInterface } from '@C/base/SFields/constant';
import './index.less';

const Index: FC<Partial<commonInterface> & Partial<CheckboxGroupProps>> = (props): ReactElement => {
  const { name, label = 'CheckboxGroup', span = 8, required = false, ruleIcon, options, formItemConfig, ...checkboxGroupProps } = props;
  const defaultOptions = [
    { label: 'A', value: 'A', },
    { label: 'B', value: 'B', },
    { label: 'C', value: 'C', },
  ];

  return (
    <Col span={span}>
      <div className="base-component-super-fields-common">
        <Form.Item
          name={name}
          label={label}
          valuePropName="checked"
          rules={getRulesConfig(required, label, ruleIcon, '请至少选择其中一项')}
          {...formItemConfig}
        >
          <Checkbox.Group options={options || defaultOptions} {...checkboxGroupProps}/>
        </Form.Item>
      </div>
    </Col>
  );
};

export default Index;
